-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build: expose VCS-related environment variables #10168
Conversation
This variable communicates what's the canonical URL for the version it's running the build. It will allow doctool/theme authors to implement the correct HTML tag required: ``` <link rel="canonical" href="" /> ``` Note the final `href` on each page will be `READTHEDOCS_CANONICAL_URL` + `page`. Closes readthedocs/readthedocs-ops#1320
Add it to the reference page.
Co-authored-by: Benjamin Balder Bach <[email protected]>
Co-authored-by: Benjamin Balder Bach <[email protected]>
Introduce 3 new variables: * `READTHEDOCS_REPOSITORY_URL` * `READTHEDOCS_REPOSITORY_IDENTIFIER` * `READTHEDOCS_REPOSITORY_IDENTIFIER_HASH` Closes #9423
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at the tests for this, and it looks solid! It's a very nice pattern to be able to expand with more environment variables 💯
I'd like the documentation to be updated with a few tweaks, but otherwise I think that these 3 environment variables are good to ship and support in the future 👍
Co-authored-by: Benjamin Balder Bach <[email protected]>
I think I accepted all the suggestions properly. -- let's see |
Yes, all looks good 👍 |
Git is weird sometimes... the base used to be |
Docs build failure = 2 warnings fixed in #10176 |
I just realized that this variable should probably be There are some use cases where we have the clone url, but we don't have the html one. They could be different and the clone url is not useful to generate links |
I did suggest it earlier :) |
We will want to expose `HTML_URL` as well, but that will require some extra work since we don't have access to `RemoteRepository` from the builder. I'm keeping it commented for now, but reserving the names.
…mitos/repository-env-variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some quibbles on the naming, but I see it's been heavily discussed already, and I didn't read the backlog 🤣 . I think the examples are 💯 for making it very explicit what we're talking about, and the names aren't hugely important.
@@ -56,6 +56,31 @@ All :doc:`build processes </builds>` have the following environment variables au | |||
:Example: ``https://docs.readthedocs.io/ja/stable/`` | |||
:Example: ``https://example--17.org.readthedocs.build/fr/17/`` | |||
|
|||
.. envvar:: READTHEDOCS_REPOSITORY_CLONE_URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we're calling it CLONE_URL, instead of REPOSITORY_URL to match the help_text?
This is the same URL defined in your Project's :term:
dashboard
in :menuselection:Admin --> Settings --> Repository URL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because the repository will also have a "web URL", i.e. the base URL for where the file can be viewed and edited, so ssh://[email protected]/repo
is different from https://frontend.com/repo/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the doc is not correct then when it says it's the same as your Repository URL in the dashboard?
Users are definitely going to be confused if it's different, but only in some cases 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Repository URL in the dashboard" is what we use as Project.repo
, which is the same of the content of this variable. Do you have a suggestion how to make this clearer? I think having all these URLs is just confusing, but necessary, tho.
I want to make the distinction between HTML_URL
and CLONE_URL
mainly because they are not going to be always the same. In community, they will mostly be the same, tho.
:Example: ``feature/signup`` | ||
:Example: ``update-readme`` | ||
|
||
.. envvar:: READTHEDOCS_REPOSITORY_IDENTIFIER_HASH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love how long this name is, but it seems reasonably explicit.
I think IDENTIFIER and HASH are kind of the same thing, but I'm not sure if git has a canonical name for this. I couldn't quickly find it in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added HASH
here to be explicit about a commit in particular. We are using IDENTIFIER
for the branch/tag name as well. I didn't find a better name for this 😞
:Example: ``https://github.com/readthedocs/readthedocs.org`` | ||
:Example: ``[email protected]:readthedocs/readthedocs.org.git`` | ||
|
||
.. envvar:: READTHEDOCS_REPOSITORY_IDENTIFIER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a repository id? Or a version ID?
This is probably the name I'm the most unclear on whether it's correct.
Again though, perfect naming is hard, and the examples tell most of the story.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like READTHEDOCS_GIT_IDENTIFIER
better. In fact I like everything better with git :)
READTHEDOCS_GIT_CLONE_URL
READTHEDOCS_GIT_COMMIT_HASH
READTHEDOCS_GIT_IDENTIFIER
it's easier to understand. I think the old VCS semi-supported backends can just have to deal with that. If we want to really support something, we might as well re-introduce "VCS" or have stuff like READTHEDOCS_HG_CLONE_URL
... but that's not relevant now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, if we wanted it to be generic, we could use VCS, but I agree GIT is probably better, and forward looking 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'm going to change the names to use GIT
👍🏼
…mitos/repository-env-variables
I'd like to think a little more if necessary, since this is something we will need to maintain for a long time 😄 . However, it seems with the latest updates, we are all in the same page and the names communicate better what we are talking about. We need to figure it out to expose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These names are much more explicit with GIT
in them 💯
We need to figure it out to expose READTHEDOCS_GIT_HTML_URL. However, I didn't want to block this PR on it because that will require a modification in the API and I'm not sure yet how to do it.
Can we copy GitHub here with naming? Is that what we're doing?
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
Via: https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-a-repository-readme
I couldn't find these names explained anywhere though 🙃 Naming is hard.
@@ -56,6 +56,31 @@ All :doc:`build processes </builds>` have the following environment variables au | |||
:Example: ``https://docs.readthedocs.io/ja/stable/`` | |||
:Example: ``https://example--17.org.readthedocs.build/fr/17/`` | |||
|
|||
.. envvar:: READTHEDOCS_GIT_CLONE_URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clearer 👍
Yes, something like that is what we are trying to follow. Hence the |
@@ -279,6 +279,9 @@ def test_get_env_vars(self, load_yaml_config, build_environment, config, externa | |||
"READTHEDOCS_OUTPUT": os.path.join( | |||
self.project.checkout_path(self.version.slug), "_readthedocs/" | |||
), | |||
"READTHEDOCS_GIT_CLONE_URL": self.project.repo, | |||
"READTHEDOCS_GIT_IDENTIFIER": self.version.identifier, | |||
"READTHEDOCS_GIT_COMMIT_HASH": self.build.commit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that the self.build.commit
is None
here?
And subprocess.popen doesn't accept a None value for environment variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that some of these values may be None if there is an error, we use docker, not sure if that also has a problem with None. Are you hitting this problem somwhere?
Introduce 3 new variables:
READTHEDOCS_REPOSITORY_URL
READTHEDOCS_REPOSITORY_IDENTIFIER
READTHEDOCS_REPOSITORY_IDENTIFIER_HASH
Closes #9423
Based on #10166
📚 Documentation previews 📚
docs
): https://docs--10168.org.readthedocs.build/en/10168/dev
): https://dev--10168.org.readthedocs.build/en/10168/